package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Order;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(value = "订单",tags ="订单接口API" )
public class AllOrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping(value = "/selectOrderAll",method = RequestMethod.POST)
    @ApiOperation(value = "查询所有订单接口",notes = "业务管理员查询",httpMethod = "POST",response = ResultJson.class)
    public ResultJson selectOrderAll(@RequestBody
     @ApiParam(name="map",value = "{order_name 订单名称(String)" +"customer_id 客户编号(int)，" +
             "commodity_id 商品编号（int）," +
             "order_state 订单状态(0：等待收货，1：完成)," +
             "order_number 数量(int) ," +
             "contract_id 合同编号(int)," +
             "create_id 创建人id(int),+" +
             "creation_time 创建时间(date)," +
             "}") Map map){
        return orderService.selectOrderAll(map);
    }

    /**
     * g订单根据ID查询
     * @param id
     * @return
     */
    @RequestMapping(value = "/selectOrderById",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID查询接口",notes = "业务员管理人员查询",httpMethod = "POST",response = ResultJson.class)
    public ResultJson selectOrderById(@RequestParam @ApiParam(name = "id",value = "订单编号") Integer id){
        return orderService.selectOrderById(id);
    }

    /**
     * 新增
     * @return
     */
    @RequestMapping(value = "/addOrder",method = RequestMethod.POST)
    @ApiOperation(value = "新增合同接口",notes = "管理人员新增",httpMethod = "POST",response = ResultJson.class)
    public ResultJson addOrder(@RequestBody @ApiParam(name = "order",value = "新增订单") Order order){
        Login login = (Login) SecurityUtils.getSubject().getPrincipal();
        System.out.println(login);
    return orderService.addOrder(order,login);
    }

    /**
     * 修改
     * @param order
     * @return
     */
    @RequestMapping(value = "/updateOrder",method = RequestMethod.POST)
    @ApiOperation(value = "修改合同接口",notes ="管理人员修改",httpMethod = "POST",response = ResultJson.class)
    public ResultJson updateOrder(@ApiParam(name = "order",value = "修改订单") Order order){
        return orderService.updateOrder(order);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteByIdOrder",method = RequestMethod.POST)
    @ApiOperation(value = "删除（修改接口）",notes="业务人员管理人员操作",httpMethod ="POST",response = ResultJson.class)
    public ResultJson deleteByIdOrder(@ApiParam(name = "id",value = "根据ID删除") Integer id){
        System.out.println("*******");
        System.out.println(id);
        return orderService.deleteByIdOrder(id);
    }
}
